package com.lanou.wuyou.gift.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.wuyou.gift.R;
import com.lanou.wuyou.gift.ormLite.Search;

import java.util.List;

/**
 * Created by dllo on 17/4/6.
 */

public class HomeFirstSearchHistoryAdapter extends BaseAdapter{
    private Context context;
    private List<Search> searches;

    public HomeFirstSearchHistoryAdapter(Context context) {
        this.context = context;
    }

    public void setSearches(List<Search> searches) {
        this.searches = searches;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return searches != null && searches.size() > 0 ? searches.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return searches.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_home_search_history,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
         holder.textView.setText(searches.get(position).getContent());
        return convertView;
    }
    class ViewHolder{
        TextView textView;
        public ViewHolder(View view){
            textView = (TextView) view.findViewById(R.id.text_home_search);
        }
    }
}
